// pages/address-list/address-list.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgBase: app.globalData.imgUrl,          // 线上图片
    localImg: app.globalData.staticimgUrl,   // 本地图片
    carts:'',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {  
    this.loadings();
  },
  compilelist: function(e) {
    var user = e.currentTarget.dataset
    app.globalData.consigneeid = user.id;
    app.globalData.consigneename = user.name;
    app.globalData.consigneephone = user.phone;
    app.globalData.consigneeaddress = user.address;    
    wx.navigateBack({
      url: '../user-shop-goods-order-1/user-shop-goods-order-1',
    })
  },
  loadings: function() {
    var that = this;
    var id = wx.getStorageSync('userid');
    // 获取用户收货人地址列表
    app.request({
      url: 'shopp/orderConsigneeApi/getConsigneeArray',
      data: {},
      method: 'GET',
      success(res) {
        that.setData({
          carts: res.data
        })
      }
    })
  },
  //删除收货人信息
  deleteClick: function(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    app.request({
      url: 'shopp/orderConsigneeApi/delConsignee',
      data: {
        id: id
      },
      success(res) {
        wx.showToast({
          title: res.message,
          icon: 'success',
          duration: 1000
        })
        setTimeout(function () {
          that.loadings();
        }, 1000)
      }
    })
  },
  //编辑收货人信息
  compile: function(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../address-add/address-add?id=' + id,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.loadings();
  }
})